package 每日一题;

/**
 * @author 会玩的洋洋
 * https://leetcode.cn/problems/evaluate-boolean-binary-tree/
 */
public class _2331_计算布尔二叉树的值 {
    /**
     * 执行用时：0ms，内存消耗：42.1MB
     * @param root
     * @return
     */
    public boolean evaluateTree(TreeNode root) {
        return preTravel(root);
    }

    private boolean preTravel(TreeNode node) {
        if (node.val == 0) {
            return false;
        } else if (node.val == 1) {
            return true;
        } else if (node.val == 2) {
            return preTravel(node.left) || preTravel(node.right);
        } else {
            return preTravel(node.left) && preTravel(node.right);
        }
    }
}
